package com.suarte.core;

import org.appfuse.model.BaseObject;
import com.suarte.utils.Persistent;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;

/**
 * @date   Jan 27, 2011
 * @author Ggutierrez
 */
@Entity @Table(name="sa_work_order_detail")
public class WorkOrderDetail extends BaseObject implements Persistent {
    private Long id;
    private WorkOrder workOrder;
    private QuotationDetail quotationDetail;
    private WorkOrderStatus status = WorkOrderStatus.EN_PRODUCCION;
    private Remission remission;

    @Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="WORK_ORDER_DETAIL_SEQ")
    @SequenceGenerator(name="WORK_ORDER_DETAIL_SEQ", sequenceName="WORK_ORDER_DETAIL_SEQ",allocationSize=1)
    public Long getId() {
        return id;
    }

    @ManyToOne
    @JoinColumn(name = "work_order_id")
    public WorkOrder getWorkOrder() {
        return workOrder;
    }

    @ManyToOne
    @JoinColumn(name = "quotation_detail_id")
    public QuotationDetail getQuotationDetail() {
        return quotationDetail;
    }

    @Enumerated(EnumType.STRING)
    @Column(name = "status")
    public WorkOrderStatus getStatus() {
        return status;
    }

    @ManyToOne
    @JoinColumn(name = "remission_id")
    public Remission getRemission() {
        return remission;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public void setWorkOrder(WorkOrder workOrder) {
        this.workOrder = workOrder;
    }

    public void setQuotationDetail(QuotationDetail quotationDetail) {
        this.quotationDetail = quotationDetail;
    }

    public void setStatus(WorkOrderStatus status) {
        this.status = status;
    }

    public void setRemission(Remission remission) {
        this.remission = remission;
    }

    @Override
    public String toString() {
        return id != null ? id.toString() : status.toString();
    }

    @Override
    public boolean equals(Object other) {
        if(other == this){
            return true;
        }
        if(!(other instanceof WorkOrderDetail)){
            return false;
        }
        WorkOrderDetail _i = (WorkOrderDetail)other;
        return id.equals(_i.id);
    }

    @Override
    public int hashCode() {
        return id.hashCode();
    }


}
